package com.example.controller;

import com.example.model.TBit;
import com.example.service.TBitServiceImpl;
import com.example.util.LikeSearchInit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Auther: yuanjianpeng
 * @Date: 2019/4/18 01:09
 * @Description:
 */
@Controller
public class TLController {

    @Autowired
    private TBitServiceImpl tBitService;

    @RequestMapping("/index")
    public String goIndex() {
        return "admin";
    }

    @RequestMapping("/data")
    @ResponseBody
    public Map<String, Object> data(@RequestParam String word) {
        Map<String, Object> result = new HashMap<>();
        List<String> tBitList = tBitService.search(word); //未优化前
//        List<String> tBitList = LikeSearchInit.likeSearch.search(word,10); //优化后，本来是Set集
        result.put("text",tBitList);
        return result;
    }

    @RequestMapping("/add")
    public int addData(@RequestBody TBit tBit) {
        return tBitService.insert(tBit);
    }

}
